/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package assign2;


import assign2.ListGUI.LoadFileListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.XMLDecoder;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import javax.swing.*;


/**
 *
 * @author martyastiadi
 */
public class ListGUI implements Runnable {

    private ArrayList<Product> product = new ArrayList <Product>();
    private ArrayList<Inventory> inventory = new ArrayList <Inventory>();
    
    public void run() {
        JFrame frame = new JFrame();
        JTextField field = new JTextField(10);
        //JButton button = new JButton("click me");
        field.setEditable(false);

        JMenuBar menu1 = new JMenuBar();
        JMenu m_product = new JMenu("Product");
        menu1.add(m_product);
        JMenuItem m_product1 = new JMenuItem("List required items");
        m_product.add(m_product1);
        JMenuItem m_product2 = new JMenuItem("Make Order");
        m_product.add(m_product2);

        //JMenu menu2 = new JMenu();
        JMenu m_print = new JMenu("Print");
        //menu1.add(m_print);
        JMenuItem m_print1 = new JMenuItem("Product List");
        m_print.add(m_print1);
        JMenuItem m_print2 = new JMenuItem("Inventory List");
        m_print.add(m_print2);
        menu1.add(m_print);

        JMenu m_file = new JMenu("File");
        JMenuItem m_file1 = new JMenuItem("Load File");
        m_file.add(m_file1);
        m_file1.addActionListener(new LoadFileListener());
        JMenuItem m_file2 = new JMenuItem("Save File");
        m_file.add(m_file2);
        menu1.add(m_file);

        JMenu m_add = new JMenu("Add");
        JMenuItem m_add1 = new JMenuItem("Inventory");
        m_add.add(m_add1);
        JMenuItem m_add2 = new JMenuItem("Product");
        m_add.add(m_add2);
        menu1.add(m_add);

        JMenu m_mess = new JMenu("Message");
        JMenuItem m_mess1 = new JMenuItem("Send Message");
        m_mess.add(m_mess1);
        JMenuItem m_mess2 = new JMenuItem("View Message");
        m_mess.add(m_mess2);
        menu1.add(m_mess);

        frame.setJMenuBar(menu1);
        frame.add(field);
        
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //frame.getContentPane().add(button);
        frame.setSize(300, 400);
        frame.setVisible(true);
        frame.repaint();
      
    }

class LoadFileListener implements ActionListener{
    public void actionPerformed(ActionEvent f){
        try{
            XMLDecoder dec = new XMLDecoder (new BufferedInputStream(new FileInputStream (new File("Inventory.xml"))));
            Object prodObject = dec.readObject();
            //dec.readObject();
            if(prodObject instanceof Product){
                Product prod = (Product)prodObject;
                System.out.println(prod.getName());
            }
        }
        catch(IOException e) {
            System.out.println ("Testing");
            System.exit(1);
            
        }
    }

    }
}

